<?php
/**
 * SGoodsModel.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/06/26
 * Time: 22:34
 */
namespace app\common\auto_curd\php_system\model;

use think\Db;

class SGoodsModel
{
    /**
     * 自增id
     */
    protected $id = '';
    public function getId()
    {
        return $this->id;
    }
    public function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * 地区配送（0不需要,1需要）
     */
    protected $region_type = '0';
    public function getRegionType()
    {
        return $this->region_type;
    }
    public function setRegionType($region_type)
    {
        $this->region_type = $region_type;
    }
    
    /**
     * 是否扣减库存（0否, 1是）
     */
    protected $is_deduction_inventory = '1';
    public function getIsDeductionInventory()
    {
        return $this->is_deduction_inventory;
    }
    public function setIsDeductionInventory($is_deduction_inventory)
    {
        $this->is_deduction_inventory = $is_deduction_inventory;
    }
    
    /**
     * 是否上架（下架后用户不可见, 0否, 1是）
     */
    protected $is_shelves = '1';
    public function getIsShelves()
    {
        return $this->is_shelves;
    }
    public function setIsShelves($is_shelves)
    {
        $this->is_shelves = $is_shelves;
    }
    
    /**
     * 是否首页推荐（0否, 1是）
     */
    protected $is_home_recommended = '0';
    public function getIsHomeRecommended()
    {
        return $this->is_home_recommended;
    }
    public function setIsHomeRecommended($is_home_recommended)
    {
        $this->is_home_recommended = $is_home_recommended;
    }
    
    /**
     * 相册图片数量
     */
    protected $photo_count = '0';
    public function getPhotoCount()
    {
        return $this->photo_count;
    }
    public function setPhotoCount($photo_count)
    {
        $this->photo_count = $photo_count;
    }
    
    /**
     * 是否已删除（0 未删除, 大于0则是删除时间）
     */
    protected $is_delete_time = '0';
    public function getIsDeleteTime()
    {
        return $this->is_delete_time;
    }
    public function setIsDeleteTime($is_delete_time)
    {
        $this->is_delete_time = $is_delete_time;
    }
    
    /**
     * 添加时间
     */
    protected $create_ts = '0';
    public function getCreateTs()
    {
        return $this->create_ts;
    }
    public function setCreateTs($create_ts)
    {
        $this->create_ts = $create_ts;
    }
    
    /**
     * 更新时间
     */
    protected $update_ts = '0';
    public function getUpdateTs()
    {
        return $this->update_ts;
    }
    public function setUpdateTs($update_ts)
    {
        $this->update_ts = $update_ts;
    }
    
    /**
     * 品牌id
     */
    protected $brand_id = '0';
    public function getBrandId()
    {
        return $this->brand_id;
    }
    public function setBrandId($brand_id)
    {
        $this->brand_id = $brand_id;
    }
    
    /**
     * 库存（所有规格库存总和）
     */
    protected $inventory = '0';
    public function getInventory()
    {
        return $this->inventory;
    }
    public function setInventory($inventory)
    {
        $this->inventory = $inventory;
    }
    
    /**
     * 购买赠送积分
     */
    protected $give_integral = '0';
    public function getGiveIntegral()
    {
        return $this->give_integral;
    }
    public function setGiveIntegral($give_integral)
    {
        $this->give_integral = $give_integral;
    }
    
    /**
     * 最低起购数量 （默认1）
     */
    protected $buy_min_number = '1';
    public function getBuyMinNumber()
    {
        return $this->buy_min_number;
    }
    public function setBuyMinNumber($buy_min_number)
    {
        $this->buy_min_number = $buy_min_number;
    }
    
    /**
     * 最大购买数量（最大数值 100000000, 小于等于0或空则不限）
     */
    protected $buy_max_number = '0';
    public function getBuyMaxNumber()
    {
        return $this->buy_max_number;
    }
    public function setBuyMaxNumber($buy_max_number)
    {
        $this->buy_max_number = $buy_max_number;
    }
    
    /**
     * 销量
     */
    protected $sales_count = '0';
    public function getSalesCount()
    {
        return $this->sales_count;
    }
    public function setSalesCount($sales_count)
    {
        $this->sales_count = $sales_count;
    }
    
    /**
     * 访问次数
     */
    protected $access_count = '0';
    public function getAccessCount()
    {
        return $this->access_count;
    }
    public function setAccessCount($access_count)
    {
        $this->access_count = $access_count;
    }
    
    /**
     * 最低原价
     */
    protected $min_original_price = '0.00';
    public function getMinOriginalPrice()
    {
        return $this->min_original_price;
    }
    public function setMinOriginalPrice($min_original_price)
    {
        $this->min_original_price = $min_original_price;
    }
    
    /**
     * 最大原价
     */
    protected $max_original_price = '0.00';
    public function getMaxOriginalPrice()
    {
        return $this->max_original_price;
    }
    public function setMaxOriginalPrice($max_original_price)
    {
        $this->max_original_price = $max_original_price;
    }
    
    /**
     * 最低价格
     */
    protected $min_price = '0.00';
    public function getMinPrice()
    {
        return $this->min_price;
    }
    public function setMinPrice($min_price)
    {
        $this->min_price = $min_price;
    }
    
    /**
     * 最高价格
     */
    protected $max_price = '0.00';
    public function getMaxPrice()
    {
        return $this->max_price;
    }
    public function setMaxPrice($max_price)
    {
        $this->max_price = $max_price;
    }
    
    /**
     * 标题颜色
     */
    protected $title_color = '';
    public function getTitleColor()
    {
        return $this->title_color;
    }
    public function setTitleColor($title_color)
    {
        $this->title_color = $title_color;
    }
    
    /**
     * 库存单位
     */
    protected $inventory_unit = '';
    public function getInventoryUnit()
    {
        return $this->inventory_unit;
    }
    public function setInventoryUnit($inventory_unit)
    {
        $this->inventory_unit = $inventory_unit;
    }
    
    /**
     * 型号
     */
    protected $model = '';
    public function getModel()
    {
        return $this->model;
    }
    public function setModel($model)
    {
        $this->model = $model;
    }
    
    /**
     * 品牌名称
     */
    protected $brand_name = '';
    public function getBrandName()
    {
        return $this->brand_name;
    }
    public function setBrandName($brand_name)
    {
        $this->brand_name = $brand_name;
    }
    
    /**
     * 标题
     */
    protected $title = '';
    public function getTitle()
    {
        return $this->title;
    }
    public function setTitle($title)
    {
        $this->title = $title;
    }
    
    /**
     * 原价（单值:10, 区间:10.00-20.00）一般用于展示使用
     */
    protected $original_price = '';
    public function getOriginalPrice()
    {
        return $this->original_price;
    }
    public function setOriginalPrice($original_price)
    {
        $this->original_price = $original_price;
    }
    
    /**
     * 销售价格（单值:10, 区间:10.00-20.00）一般用于展示使用
     */
    protected $price = '';
    public function getPrice()
    {
        return $this->price;
    }
    public function setPrice($price)
    {
        $this->price = $price;
    }
    
    /**
     * 分类树形描述(,1,2,3,)
     */
    protected $category_tree = '';
    public function getCategoryTree()
    {
        return $this->category_tree;
    }
    public function setCategoryTree($category_tree)
    {
        $this->category_tree = $category_tree;
    }
    
    /**
     * 分类名称树形描述(,name1,name2,name3,)
     */
    protected $category_name_tree = '';
    public function getCategoryNameTree()
    {
        return $this->category_name_tree;
    }
    public function setCategoryNameTree($category_name_tree)
    {
        $this->category_name_tree = $category_name_tree;
    }
    
    /**
     * 封面图片
     */
    protected $images = '';
    public function getImages()
    {
        return $this->images;
    }
    public function setImages($images)
    {
        $this->images = $images;
    }
    
    /**
     * 短视频
     */
    protected $video = '';
    public function getVideo()
    {
        return $this->video;
    }
    public function setVideo($video)
    {
        $this->video = $video;
    }
    
    /**
     * 规格列参数
     */
    protected $spec_cols = '';
    public function getSpecCols()
    {
        return $this->spec_cols;
    }
    public function setSpecCols($spec_cols)
    {
        $this->spec_cols = $spec_cols;
    }
    
    /**
     * 首页推荐图片
     */
    protected $home_recommended_images = '';
    public function getHomeRecommendedImages()
    {
        return $this->home_recommended_images;
    }
    public function setHomeRecommendedImages($home_recommended_images)
    {
        $this->home_recommended_images = $home_recommended_images;
    }
    
    /**
     * 自定义属性
     */
    protected $attr_list = '';
    public function getAttrList()
    {
        return $this->attr_list;
    }
    public function setAttrList($attr_list)
    {
        $this->attr_list = $attr_list;
    }
    
    /**
     * 相册
     */
    protected $photo_list = '';
    public function getPhotoList()
    {
        return $this->photo_list;
    }
    public function setPhotoList($photo_list)
    {
        $this->photo_list = $photo_list;
    }
    
    /**
     * 配送区域
     */
    protected $region_list = '';
    public function getRegionList()
    {
        return $this->region_list;
    }
    public function setRegionList($region_list)
    {
        $this->region_list = $region_list;
    }
    
    /**
     * 电脑端详情内容
     */
    protected $content_web = '';
    public function getContentWeb()
    {
        return $this->content_web;
    }
    public function setContentWeb($content_web)
    {
        $this->content_web = $content_web;
    }
    
    /**
     * constructor.
     * @param array $data
     */
    public function __construct($data=[])
    {

        // 自增id
        if(isset($data['id']))
        {
            $this->id = $data['id'];
        }

        // 地区配送（0不需要,1需要）
        if(isset($data['region_type']))
        {
            $this->region_type = $data['region_type'];
        }

        // 是否扣减库存（0否, 1是）
        if(isset($data['is_deduction_inventory']))
        {
            $this->is_deduction_inventory = $data['is_deduction_inventory'];
        }

        // 是否上架（下架后用户不可见, 0否, 1是）
        if(isset($data['is_shelves']))
        {
            $this->is_shelves = $data['is_shelves'];
        }

        // 是否首页推荐（0否, 1是）
        if(isset($data['is_home_recommended']))
        {
            $this->is_home_recommended = $data['is_home_recommended'];
        }

        // 相册图片数量
        if(isset($data['photo_count']))
        {
            $this->photo_count = $data['photo_count'];
        }

        // 是否已删除（0 未删除, 大于0则是删除时间）
        if(isset($data['is_delete_time']))
        {
            $this->is_delete_time = $data['is_delete_time'];
        }

        // 添加时间
        if(isset($data['create_ts']))
        {
            $this->create_ts = $data['create_ts'];
        }

        // 更新时间
        if(isset($data['update_ts']))
        {
            $this->update_ts = $data['update_ts'];
        }

        // 品牌id
        if(isset($data['brand_id']))
        {
            $this->brand_id = $data['brand_id'];
        }

        // 库存（所有规格库存总和）
        if(isset($data['inventory']))
        {
            $this->inventory = $data['inventory'];
        }

        // 购买赠送积分
        if(isset($data['give_integral']))
        {
            $this->give_integral = $data['give_integral'];
        }

        // 最低起购数量 （默认1）
        if(isset($data['buy_min_number']))
        {
            $this->buy_min_number = $data['buy_min_number'];
        }

        // 最大购买数量（最大数值 100000000, 小于等于0或空则不限）
        if(isset($data['buy_max_number']))
        {
            $this->buy_max_number = $data['buy_max_number'];
        }

        // 销量
        if(isset($data['sales_count']))
        {
            $this->sales_count = $data['sales_count'];
        }

        // 访问次数
        if(isset($data['access_count']))
        {
            $this->access_count = $data['access_count'];
        }

        // 最低原价
        if(isset($data['min_original_price']))
        {
            $this->min_original_price = $data['min_original_price'];
        }

        // 最大原价
        if(isset($data['max_original_price']))
        {
            $this->max_original_price = $data['max_original_price'];
        }

        // 最低价格
        if(isset($data['min_price']))
        {
            $this->min_price = $data['min_price'];
        }

        // 最高价格
        if(isset($data['max_price']))
        {
            $this->max_price = $data['max_price'];
        }

        // 标题颜色
        if(isset($data['title_color']))
        {
            $this->title_color = $data['title_color'];
        }

        // 库存单位
        if(isset($data['inventory_unit']))
        {
            $this->inventory_unit = $data['inventory_unit'];
        }

        // 型号
        if(isset($data['model']))
        {
            $this->model = $data['model'];
        }

        // 品牌名称
        if(isset($data['brand_name']))
        {
            $this->brand_name = $data['brand_name'];
        }

        // 标题
        if(isset($data['title']))
        {
            $this->title = $data['title'];
        }

        // 原价（单值:10, 区间:10.00-20.00）一般用于展示使用
        if(isset($data['original_price']))
        {
            $this->original_price = $data['original_price'];
        }

        // 销售价格（单值:10, 区间:10.00-20.00）一般用于展示使用
        if(isset($data['price']))
        {
            $this->price = $data['price'];
        }

        // 分类树形描述(,1,2,3,)
        if(isset($data['category_tree']))
        {
            $this->category_tree = $data['category_tree'];
        }

        // 分类名称树形描述(,name1,name2,name3,)
        if(isset($data['category_name_tree']))
        {
            $this->category_name_tree = $data['category_name_tree'];
        }

        // 封面图片
        if(isset($data['images']))
        {
            $this->images = $data['images'];
        }

        // 短视频
        if(isset($data['video']))
        {
            $this->video = $data['video'];
        }

        // 规格列参数
        if(isset($data['spec_cols']))
        {
            $this->spec_cols = $data['spec_cols'];
        }

        // 首页推荐图片
        if(isset($data['home_recommended_images']))
        {
            $this->home_recommended_images = $data['home_recommended_images'];
        }

        // 自定义属性
        if(isset($data['attr_list']))
        {
            $this->attr_list = $data['attr_list'];
        }

        // 相册
        if(isset($data['photo_list']))
        {
            $this->photo_list = $data['photo_list'];
        }

        // 配送区域
        if(isset($data['region_list']))
        {
            $this->region_list = $data['region_list'];
        }

        // 电脑端详情内容
        if(isset($data['content_web']))
        {
            $this->content_web = $data['content_web'];
        }

    }
    
    /**
     * 获取分页信息
     * @param $where
     * @param array $extend
     * @return \think\Paginator
     */
    static public function paginate($where,$extend=[])
    {
        $handler = Db::table('s_goods');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        if(!empty($extend['order']))
        {
            $handler->order($extend['order']);
        }
        if(!empty($extend['group']))
        {
            $handler->group($extend['group']);
        }
        return $handler
            ->where($where)
            ->paginate();
    }
    
    /**
     * 添加|修改
     * @param $flag
     * @param $data
     * @param array $extend
     * @return int|string
     */
    static public function save($flag,$data,$extend=[])
    {
        if(empty($flag))
        {
            // 添加
            $data['create_ts'] = time();
            return Db::table('s_goods')
                ->insertGetId($data);
        }
        else
        {
            // 编辑
            $data['update_ts'] = time();
            return Db::table('s_goods')
                ->where('id',$flag)
                ->update($data);
        }
    }
    
    /**
     * 获取详情
     * @param $where
     * @param array $extend
     * @return array|false|null|\PDOStatement|string|\think\Model
     */
    static public function get($where,$extend=[])
    {
        $handler = Db::table('s_goods');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        if(!empty($extend['order']))
        {
            $handler->order($extend['order']);
        }
        if(!empty($extend['group']))
        {
            $handler->group($extend['group']);
        }
        return $handler
            ->where($where)
            ->find();
    }
    
    /**
     * 删除
     * @param $flag
     * @param array $extend
     * @return int
     */
    static public function delete($flag,$extend=[])
    {
        return Db::table('s_goods')
            ->where('id',$flag)
            ->delete();
    }
}